home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2004 April / SGI IRIX 6.5 Applications 2004 April.iso / dist / mozilla.idb / var / netscape / mozilla / chrome / toolkit.jar.z / toolkit.jar / content / global / consoleBindings.xml < prev    next >
Extensible Markup Language  |  2003-11-11  |  14KB  |  404 lines

  1. <?xml version="1.0"?>
  2.  
  3. <!DOCTYPE window SYSTEM "chrome://global/locale/console.dtd">
  4.  
  5. <bindings id="consoleBindings"
  6.           xmlns="http://www.mozilla.org/xbl"
  7.           xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  8.           xmlns:xbl="http://www.mozilla.org/xbl">
  9.  
  10.   <binding id="console-box" extends="xul:box">
  11.     <content>  
  12.       <xul:stringbundle src="chrome://global/locale/console.properties" role="string-bundle"/>
  13.       <xul:vbox class="console-box-internal">
  14.         <xul:vbox class="console-rows" role="console-rows" xbl:inherits="dir=sortOrder"/>
  15.       </xul:vbox>
  16.     </content>
  17.   
  18.     <implementation>
  19.       <field name="limit" readonly="true">
  20.         250
  21.       </field>
  22.       <field name="_showChromeErrors">-1</field>
  23.       
  24.       <property name="showChromeErrors">
  25.         <getter><![CDATA[
  26.           if (this._showChromeErrors != -1)
  27.             return this._showChromeErrors;
  28.           var pref = Components.classes['@mozilla.org/preferences-service;1'].getService();
  29.           pref = pref.QueryInterface(Components.interfaces.nsIPrefBranch);
  30.  
  31.           try {
  32.             return this._showChromeErrors = pref.getBoolPref("javascript.options.showInConsole");
  33.           }
  34.           catch(ex) {
  35.             return this._showChromeErrors = false;
  36.           }
  37.         ]]></getter>
  38.       </property>          
  39.  
  40.       <property name="count" readonly="true">
  41.         <getter>return this.mCount</getter>
  42.       </property>
  43.     
  44.       <property name="mode">
  45.         <getter>return this.mMode;</getter>
  46.         <setter><![CDATA[
  47.           this.mMode = val || "All";
  48.           this.setAttribute("mode", this.mMode);
  49.           return val;
  50.         ]]></setter>
  51.       </property>
  52.     
  53.       <property name="sortOrder">
  54.         <getter>return this.getAttribute("sortOrder");</getter>
  55.         <setter>this.setAttribute("sortOrder", val); return val;</setter>
  56.       </property>
  57.       <field name="mSelectedItem">null</field>
  58.       <property name="selectedItem">
  59.         <getter>return this.mSelectedItem</getter>
  60.         <setter><![CDATA[
  61.           if (this.mSelectedItem)
  62.             this.mSelectedItem.removeAttribute("selected");
  63.           
  64.           this.mSelectedItem = val;
  65.           val.setAttribute("selected", "true");
  66.         ]]></setter>
  67.       </property>
  68.     
  69.       <method name="init">
  70.         <body><![CDATA[
  71.           this.mCount = 0;
  72.           
  73.           this.mConsoleListener = {
  74.             console: this, 
  75.             observe : function(aObject) { this.console.appendItem(aObject); }
  76.           };
  77.           
  78.           this.mConsoleRowBox = this.getAnonElByAttr("role", "console-rows");
  79.           this.mStrBundle = this.getAnonElByAttr("role", "string-bundle");
  80.           
  81.           try {
  82.             var isupports = Components.classes['@mozilla.org/consoleservice;1'].getService();
  83.             this.mCService = isupports.QueryInterface(Components.interfaces.nsIConsoleService);
  84.             this.mCService.registerListener(this.mConsoleListener);
  85.           } catch (ex) {
  86.             appendItem(
  87.               "Unable to display errors - couldn't get Console Service component. " +
  88.               "(Missing @mozilla.org/consoleservice;1)");
  89.             return;
  90.           }          
  91.                     
  92.           this.mMode = this.getAttribute("mode") || "All";
  93.  
  94.           this.appendInitialItems();
  95.         ]]></body>
  96.       </method>
  97.     
  98.       <method name="destroy">
  99.         <body><![CDATA[
  100.           this.mCService.unregisterListener(this.mConsoleListener);
  101.         ]]></body>
  102.       </method>
  103.     
  104.       <method name="appendInitialItems">
  105.         <body><![CDATA[
  106.           var out = {}; // Throwaway references to support 'out' parameters.
  107.           this.mCService.getMessageArray(out, {});
  108.           var messages = out.value;
  109.       
  110.           // In case getMessageArray returns 0-length array as null
  111.           if (!messages)
  112.             messages = [];
  113.       
  114.           var limit = messages.length - this.limit;
  115.           if (limit < 0) limit = 0;
  116.         
  117.           // Checks if console ever been cleared
  118.           for (var i = messages.length - 1; i >= limit; --i)
  119.             if (!messages[i].message)
  120.               break;
  121.         
  122.           // Populate with messages after latest "clear"
  123.           while (++i < messages.length)
  124.             this.appendItem(messages[i]);
  125.         ]]></body>
  126.       </method>
  127.  
  128.       <method name="appendItem">
  129.         <parameter name="aObject"/>
  130.         <body><![CDATA[
  131.           if (!aObject.message) return;
  132.  
  133.           try {
  134.             // Try to QI it to a script error to get more info
  135.             var scriptError = aObject.QueryInterface(Components.interfaces.nsIScriptError);
  136.             
  137.             // filter chrome urls
  138.             if (!this.showChromeErrors && scriptError.sourceName.substr(0, 9) == "chrome://")
  139.               return;
  140.  
  141.             this.appendError(scriptError);
  142.           } catch (ex) {
  143.             try {
  144.               // Try to QI it to a console message
  145.               var msg = aObject.QueryInterface(Components.interfaces.nsIConsoleMessage);
  146.               this.appendMessage(msg.message);
  147.             } catch (ex2) {
  148.               // Give up and append the object itself as a string
  149.               this.appendMessage(aObject);
  150.             }
  151.           }
  152.         ]]></body>
  153.       </method>
  154.  
  155.       <method name="appendError">
  156.         <parameter name="aObject"/>
  157.         <body><![CDATA[
  158.           var row = this.createConsoleRow();
  159.           var nsIScriptError = Components.interfaces.nsIScriptError;
  160.           
  161.           // Is this error actually just a non-fatal warning?
  162.           var warning = aObject.flags & nsIScriptError.warningFlag != 0;
  163.   
  164.           var typetext = warning ? "typeWarning" : "typeError";
  165.           row.setAttribute("typetext", this.mStrBundle.getString(typetext));
  166.           row.setAttribute("type", warning ? "warning" : "error");
  167.           row.setAttribute("msg", aObject.message);
  168.           if (aObject.lineNumber || aObject.sourceName) {
  169.             row.setAttribute("url", aObject.sourceName);
  170.             row.setAttribute("line", aObject.lineNumber);
  171.           } else {
  172.             row.setAttribute("hideSource", "true");
  173.           }
  174.           if (aObject.sourceLine) {
  175.             row.setAttribute("code", aObject.sourceLine.replace("\n", "", "g"));
  176.             if (aObject.columnNumber) {
  177.               row.setAttribute("col", aObject.columnNumber);
  178.               row.setAttribute("errorDots", this.repeatChar(" ", aObject.columnNumber));
  179.               row.setAttribute("errorCaret", " ");
  180.             } else {
  181.               row.setAttribute("hideCaret", "true");
  182.             }
  183.           } else {
  184.             row.setAttribute("hideCode", "true");
  185.           }
  186.           this.appendConsoleRow(row);
  187.         ]]></body>
  188.       </method>
  189.             
  190.       <method name="appendMessage">
  191.         <parameter name="aMessage"/>
  192.         <parameter name="aType"/>
  193.         <body><![CDATA[
  194.           var row = this.createConsoleRow();
  195.           row.setAttribute("type", aType || "message");
  196.           row.setAttribute("msg", aMessage);
  197.           this.appendConsoleRow(row);
  198.         ]]></body>
  199.       </method>
  200.       
  201.       <method name="clear">
  202.         <body><![CDATA[
  203.           this.mCService.logStringMessage(null);
  204.           this.mCount = 0;
  205.           
  206.           var newRows = this.mConsoleRowBox.cloneNode(false);
  207.           this.mConsoleRowBox.parentNode.replaceChild(newRows, this.mConsoleRowBox);
  208.           this.mConsoleRowBox = newRows;
  209.         ]]></body>
  210.       </method>
  211.             
  212.       <method name="copySelectedItem">
  213.         <body><![CDATA[
  214.           if (this.mSelectedItem) try {
  215.             const clipURI = "@mozilla.org/widget/clipboardhelper;1";
  216.             const clipI = Components.interfaces.nsIClipboardHelper;
  217.             var clipboard = Components.classes[clipURI].getService(clipI);
  218.  
  219.             clipboard.copyString(this.mSelectedItem.toString());
  220.           } catch (ex) {
  221.             // Unable to copy anything, die quietly
  222.           }
  223.         ]]></body>
  224.       </method>
  225.                   
  226.       <method name="createConsoleRow">
  227.         <body><![CDATA[
  228.           var row = document.createElement("box");
  229.           row.setAttribute("class", "console-row");
  230.           row._IsConsoleRow = true;
  231.           row._ConsoleBox = this;
  232.           return row;
  233.         ]]></body>
  234.       </method>
  235.             
  236.       <method name="appendConsoleRow">
  237.         <parameter name="aRow"/>
  238.         <body><![CDATA[
  239.           this.mConsoleRowBox.appendChild(aRow);
  240.           if (++this.mCount > this.limit) this.deleteFirst();
  241.         ]]></body>
  242.       </method>
  243.             
  244.       <method name="deleteFirst">
  245.         <body><![CDATA[
  246.           var node = this.mConsoleRowBox.firstChild;
  247.           this.mConsoleRowBox.removeChild(node);
  248.           --this.mCount;
  249.         ]]></body>
  250.       </method>
  251.             
  252.       <!-- UTILITY FUNCTIONS -->
  253.       
  254.       <!-- We need this method only because document.getAnonymousElementByAttribute 
  255.           is crashing (as of 2/26/2001) -->
  256.       <method name="getAnonElByAttr">
  257.         <parameter name="aAttr"/>
  258.         <parameter name="aVal"/>
  259.         <body><![CDATA[
  260.           var kids = document.getAnonymousNodes(this);
  261.           for (var i = 0; i < kids.length; ++i) {
  262.             if (kids[i].getAttribute(aAttr) == aVal)
  263.               return kids[i];
  264.             var kids2 = kids[i].getElementsByAttribute(aAttr, aVal);
  265.             if (kids2.length > 0)
  266.               return kids2[0];
  267.           }
  268.           return null;
  269.         ]]></body>
  270.       </method>
  271.  
  272.       <method name="repeatChar">
  273.         <parameter name="aChar"/>
  274.         <parameter name="aCol"/>
  275.         <body><![CDATA[
  276.           var str = "";
  277.           if (aCol)
  278.             for (var i = 1; i < aCol; ++i)
  279.               str += aChar;
  280.           
  281.           return str;
  282.         ]]></body>
  283.       </method>
  284.           
  285.       <constructor> this.init(); </constructor>
  286.       <destructor> this.destroy(); </destructor>
  287.     </implementation>
  288.     
  289.     <handlers>
  290.       <handler event="mousedown"><![CDATA[
  291.         if (event.button == 0 || event.button == 2) {
  292.           var target = event.originalTarget;
  293.   
  294.           while (target && !("_IsConsoleRow" in target))
  295.             target = target.parentNode;
  296.  
  297.           if (target)
  298.             this.selectedItem = target;
  299.         }
  300.       ]]></handler>
  301.     </handlers>
  302.   </binding>
  303.  
  304.   <binding id="error" extends="xul:box">
  305.     <content>
  306.       <xul:box class="console-row-internal-box" flex="1">
  307.         <xul:box class="console-row-icon" align="center" xbl:inherits="selected">
  308.           <xul:image class="console-icon" xbl:inherits="src,type"/>
  309.         </xul:box>
  310.         <xul:vbox class="console-row-content" xbl:inherits="selected" flex="1">
  311.           <xul:box class="console-row-msg" align="start">
  312.             <xul:label class="label" xbl:inherits="value=typetext"/>
  313.             <xul:description class="console-error-msg" xbl:inherits="value=msg" flex="1"/>
  314.           </xul:box>
  315.           <xul:box class="console-row-file" xbl:inherits="hidden=hideSource">
  316.             <xul:label class="label" value="&errFile.label;"/>
  317.             <xul:box class="console-error-source" xbl:inherits="url,line"/>
  318.             <spacer flex="1"/>
  319.             <xul:label class="label" value="&errLine.label;"/>
  320.             <xul:label class="label" xbl:inherits="value=line" flex="1"/>
  321.           </xul:box>
  322.           <xul:vbox class="console-row-code" xbl:inherits="selected,hidden=hideCode">
  323.             <xul:label class="monospace console-code" xbl:inherits="value=code"/>
  324.             <xul:box xbl:inherits="hidden=hideCaret">
  325.               <xul:label class="monospace console-dots" xbl:inherits="value=errorDots"/>
  326.               <xul:label class="monospace console-caret" xbl:inherits="value=errorCaret"/>
  327.               <xul:spacer flex="1"/>
  328.             </xul:box>
  329.           </xul:vbox>
  330.         </xul:vbox>
  331.       </xul:box>
  332.     </content>
  333.  
  334.     <implementation>
  335.       
  336.       <method name="toString">
  337.         <body><![CDATA[
  338.           var msg = this.getAttribute("typetext") + " " + this.getAttribute("msg");
  339.           
  340.           var strBundle = this._ConsoleBox.mStrBundle;
  341.           
  342.           if (this.hasAttribute("line") && this.hasAttribute("url")) {
  343.             msg += "\n" + strBundle.getFormattedString("errFile", 
  344.                                         [this.getAttribute("url")]) + "\n";
  345.             if (this.hasAttribute("col")) {
  346.               msg += strBundle.getFormattedString("errLineCol",
  347.                          [this.getAttribute("line"), this.getAttribute("col")]);
  348.             } else
  349.               msg += strBundle.getFormattedString("errLine", [this.getAttribute("line")]);
  350.           }
  351.           
  352.           if (this.hasAttribute("code"))
  353.             msg += "\n" + strBundle.getString("errCode") + "\n" + this.getAttribute("code");
  354.           
  355.           return msg;
  356.         ]]></body>
  357.       </method>
  358.       
  359.     </implementation>
  360.     
  361.   </binding>
  362.   
  363.   <binding id="message" extends="xul:box">
  364.     <content>
  365.       <xul:box class="console-internal-box" flex="1">
  366.         <xul:box class="console-row-icon" align="center">
  367.           <xul:image class="console-icon" xbl:inherits="src,type"/>
  368.         </xul:box>
  369.         <xul:vbox class="console-row-content" xbl:inherits="selected" flex="1">
  370.           <xul:vbox class="console-row-msg" flex="1">
  371.             <xul:description class="console-msg-text" xbl:inherits="value=msg" flex="1"/>
  372.           </xul:vbox>
  373.         </xul:vbox>
  374.       </xul:box>
  375.     </content>
  376.  
  377.     <implementation>
  378.       <method name="toString">
  379.         <body><![CDATA[
  380.           return this.getAttribute("msg");
  381.         ]]></body>
  382.       </method>
  383.     </implementation>
  384.   </binding>
  385.  
  386.   <binding id="console-error-source" extends="xul:box">
  387.     <content>
  388.       <xul:label class="text-link" xbl:inherits="value=url" crop="right"/>
  389.     </content>
  390.  
  391.     <handlers>
  392.       <handler event="click"><![CDATA[
  393.           var url = this.getAttribute("url");
  394.           var line = getAttribute("line");  
  395.           window.openDialog(
  396.             "chrome://navigator/content/viewSource.xul", "_blank", 
  397.             "scrollbars,resizable,chrome,dialog=no", url, null, null, line);
  398.       ]]></handler>
  399.     </handlers>
  400.   </binding>
  401.  
  402. </bindings>
  403.  
  404.